package com.lianzhihui.romeex.ui.account;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.base.AppConfig;
import com.lianzhihui.romeex.config.AppConstants;
import com.lianzhihui.romeex.config.MessageEvent;
import com.lianzhihui.romeex.database.DataBaseManager;
import com.lianzhihui.romeex.inter.DialogListener;
import com.lianzhihui.romeex.ui.base.BaseActivity;
import com.lianzhihui.romeex.utils.MyToast;
import com.lianzhihui.romeex.utils.UserUtils;
import com.lianzhihui.romeex.widget.dialog.PasswordDialog;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * Description:
 * Author: RAMON
 * CreateDate: 2020/11/2 4:00pm
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class WalletSettingActivity extends BaseActivity {

    @BindView(R.id.ll_change_name)
    LinearLayout ll_change_name;
    @BindView(R.id.ll_mod_safty)
    LinearLayout ll_mod_safty;
    @BindView(R.id.ll_export)
    LinearLayout ll_export;

    @BindView(R.id.bt_del)
    Button bt_del;

    String address;
    boolean last;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_wallet_setting;
    }

    @Override
    protected void initView() {
        setTitle(getString(R.string.edit_wallet));
        Intent intent = getIntent();
        address = intent.getStringExtra(AppConfig.ADDRESS);
        if(address.equals(UserUtils.getCurrentUserAddress())){
            bt_del.setVisibility(View.GONE);
        }
        last = intent.getBooleanExtra(AppConfig.IS_LAST, true);
        if (TextUtils.isEmpty(address)) {
            MyToast.showToast("数据错误");
            finish();
        }
        if (last) {
            bt_del.setVisibility(View.GONE);
        }
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.bt_del, R.id.ll_change_name, R.id.ll_mod_safty, R.id.ll_export})
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.bt_del:
                PasswordDialog dialog = new PasswordDialog(this, getString(R.string.input_password));
                dialog.setListener(new DialogListener() {
                    @Override
                    public void onPassed() {
                        DataBaseManager.del_WalletToDbSnyc(address);
                        EventBus.getDefault().post(new MessageEvent(AppConstants.Event.REFRUSH_WALLET, true));
                        finish();
                    }

                    @Override
                    public void onFail() {

                    }
                });
                dialog.show();
                break;

            case R.id.ll_change_name:
                //修改昵称
                startActivity(new Intent(mActivity, ChangeNameActivity.class).putExtra(AppConfig.ADDRESS, address));
                break;
            case R.id.ll_mod_safty:
                //修改安全码
                startActivity(new Intent(mActivity, ModSaftyActivity.class).putExtra(AppConfig.ADDRESS, address));
                break;
            case R.id.ll_export:

                PasswordDialog dialog3 = new PasswordDialog(this, getString(R.string.input_password));
                dialog3.setListener(new DialogListener() {
                    @Override
                    public void onPassed() {
                        Intent intent = new Intent(mActivity, ExportWordPKActivity.class);
                        intent.putExtra(AppConfig.ADDRESS, address);
                        startActivity(intent);
                    }

                    @Override
                    public void onFail() {

                    }
                });
                dialog3.show();
                break;
            default:
                break;
        }
    }

}
